﻿using System;
using System.Data;
using VanTaiBLL;
using VanTaiProperty;

namespace VanTaiTMS.Page
{
    public partial class SendMailDeNghiSuaChua2 : System.Web.UI.Page
    {
        #region[KhaiBao]
        private DataTable dtSendMail;
        private DataTable dtMailConfig;
        protected string StrAlertSendMail = "";
        readonly clsTMRepair_SuggestionBusiness clsSendMail = new clsTMRepair_SuggestionBusiness();
        private readonly TMMAIL_CONFIG_BusinessLogic clsMailConfig = new TMMAIL_CONFIG_BusinessLogic();
        #endregion

        #region[Controller]
        protected void Page_Load(object sender, EventArgs e)
        {
            lbTrangThaiDuyet.Visible = false;
            lbTrangThaiDuyet2.Visible = false;
            lbMailPhanCap1.Visible = false;
            lbMailPhanCap2.Visible = false;
            int id;
            if (Int32.TryParse(Request.Params["id"], out id))
            {
                if (!IsPostBack)
                {
                    DeNghiSuaChuaDetail(int.Parse(Request.Params["id"]));
                    //Browser();
                }
            }
        }
        protected void cmdSendMail_Click(object sender, EventArgs e)
        {
            Browser();
        }
        protected void cmdHuy_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }
        #endregion

        #region[Function]
        protected void DeNghiSuaChuaDetail(int id)
        {
            dtSendMail = clsSendMail.BindGirdTMRepair_SuggestionDetail(id);
            if (dtSendMail != null && dtSendMail.Rows.Count > 0)
            {
                //lbTrangThaiDuyet2.Text = dtSendMail.Rows[0]["DommandTransferOrder_Level_2"].ToString();
                lbTrangThaiDuyet.Text = dtSendMail.Rows[0]["Repair_Suggestion_Status"].ToString();
                lbMailPhanCap1.Text = dtSendMail.Rows[0]["Email_Receice1"].ToString();
                lbMailPhanCap2.Text = dtSendMail.Rows[0]["Email_Receice2"].ToString();
                //---------------------
                lbChungTu.Text = dtSendMail.Rows[0]["Repair_Suggestion_ID"].ToString();
                lbNgayDeNghi.Text = String.Format("{0:dd-MM-yyyy}", dtSendMail.Rows[0]["Repair_Suggestion_Date"]);
                lbSoXe.Text = dtSendMail.Rows[0]["Vehicle_Number"].ToString();
                lbTaiXe.Text = dtSendMail.Rows[0]["FullNameMem"].ToString();
                lbNhomXe.Text = dtSendMail.Rows[0]["VehicleGroup_Name"].ToString();
                lbLoaiVatTuThayThe.Text = dtSendMail.Rows[0]["RepairMaterials_Name"].ToString();
                lbKyHieuLoaiVatTu.Text = dtSendMail.Rows[0]["SymbolRepairMaterials_Name"].ToString();
                lbQuocGia.Text = dtSendMail.Rows[0]["National_Name"].ToString();
                lbSoLuong.Text = dtSendMail.Rows[0]["Repair_Suggestion_Quantity"].ToString();
                lbDonGia.Text = dtSendMail.Rows[0]["Repair_Suggestion_Rate"].ToString();
                lbChiPhi.Text = dtSendMail.Rows[0]["Repair_Suggestion_Cost"].ToString();
                lbGhiChu.Text = dtSendMail.Rows[0]["Repair_Suggestion_Note"].ToString();
            }
        }
        protected void UpdateTrangThaiDuyet()
        {
            var obj = new clsTMRepair_SuggestionProperty
            {
                Repair_Suggestion_ID = float.Parse(lbChungTu.Text),
                Repair_Suggestion_Status = 3
            };
            clsTMRepair_SuggestionBusiness.UpdateStatusTMRepair_Suggestion(obj);
            StrAlertSendMail += "<div class='alert alert-warning'>";
            StrAlertSendMail += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
            StrAlertSendMail += "Duyệt trạng thái thành công !";
            StrAlertSendMail += "</div>";
            DeNghiSuaChuaDetail(int.Parse(Request.Params["id"]));
        }

        protected void Browser()
        {
            dtMailConfig = clsMailConfig.BindGridMail();
            if (dtMailConfig != null && dtMailConfig.Rows.Count > 0)
            {
                if (lbTrangThaiDuyet.Text == "1")
                {
                    //UpdateTrangThaiDuyet_GD();
                    StrAlertSendMail += "<div class='alert alert-warning'>";
                    StrAlertSendMail += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                    StrAlertSendMail += "Lệnh điều động chưa được trưởng phòng xét duyệt !";
                    StrAlertSendMail += "</div>";
                }
                if (lbTrangThaiDuyet.Text == "2" && lbTrangThaiDuyet.Text != "3")
                {
                    UpdateTrangThaiDuyet();
                    //StrAlertSendMail += "<div class='alert alert-warning'>";
                    //StrAlertSendMail += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                    //StrAlertSendMail += "Lệnh điều động chưa được xét duyệt !";
                    //StrAlertSendMail += "</div>";
                }
                if (lbTrangThaiDuyet.Text == "3")
                {
                    StrAlertSendMail += "<div class='alert alert-warning'>";
                    StrAlertSendMail += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                    StrAlertSendMail += "Lệnh xét duyệt này đã được trưởng phòng và giám đốc thông qua !";
                    StrAlertSendMail += "</div>";
                }
            }
        }
        #endregion
    }
}